<template>
  <view v-if="listData.length > 0">
    <view class="grid-body mt-30" v-for="item in listData" :key="item.id">
      <view class="check grid-common">
        <view class="title flex">
          <image class="icon-style" src="/static/images/icon1.png" mode="aspectFill"></image>{{ item.projectName }}
        </view>
        <view class="flex text"
          >项目编号：<text> {{ item.projectCode }}</text></view
        >
        <view class="flex text"
          >所属部门：<text>{{ item.deptName }}</text></view
        >
        <view class="flex text"
          >所属区域：<text>{{ item.areaName }}</text></view
        >
        <view class="flex text"
          >项目日期：<text> {{ item.projectDate }}</text></view
        >
        <view class="flex text"
          >审批状态：<text> {{ item.checkStatusLabel }}</text></view
        >
        <view class="flex text"
          >待办人：<text> {{ item.auditorName }}</text></view
        >
        <view class="flex text bor-top">
          <button class="info-btn" @click="goDetail(item.projectId, item.projectInfoId)">处理</button>
        </view>
      </view>
    </view>
  </view>
  <view v-else><Empty></Empty></view>
</template>

<script>
import Empty from '@/components/cu-empty/index.vue'
import { getApproveList } from '../../../api/spw/project'
export default {
  components: {
    Empty
  },
  data() {
    return {
      listData: [],
      pageNum: 1,
      total: null
    }
  },
  onLoad() {
    this.initData()
  },
  onPullDownRefresh() {
    this.initData()
  },
  onReachBottom() {
    this.pageNum++
    this.getList()
  },
  methods: {
    initData() {
      this.pageNum = 1
      this.total = null
      this.getList()
    },
    getList() {
      if (!this.total || this.total > this.listData.length) {
        getApproveList({
          pageNum: this.pageNum
        }).then((res) => {
          if (this.pageNum === 1) {
            this.listData = res.rows
          } else {
            this.listData.push(...res.rows)
          }
          this.total = res.total
          uni.stopPullDownRefresh()
        })
      }
    },
    goDetail(projectId, projectInfoId) {
      uni.navigateTo({
        url: '/pages/jobSlip/work-project/approve?projectId=' + projectId + '&projectInfoId=' + projectInfoId,
        events: {
          // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
          'callback:reload': () => {
            this.initData()
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.check {
  position: relative;

  .title {
    font-size: 34rpx;
    font-weight: 700;
  }

  .icon-style {
    width: 52rpx;
    height: 52rpx;
    margin-right: 20rpx;
  }

  .text {
    color: #999;

    text {
      width: 60%;
      color: #333;
      display: inline-block;
    }
  }

  .bor-top {
    padding-top: 20rpx;
    border-top: 1px solid #d5d7e3;
  }

  .check-right-top {
    position: absolute;
    right: 20rpx;
    top: 40rpx;

    image {
      width: 100rpx;
      height: 88rpx;
    }
  }
}
</style>
